﻿/***
无名智者个人博客 - Super-Ublog-Black - JavaScript 函数库
作者：无名智者
Email:Kenvix@vip.qq.com
***/
// 获取URL GET参数
function urlget(argname) {
var url = document.location.href;
var arrStr = url.substring(url.indexOf("?")+1).split("&");
for(var i =0;i<arrStr.length;i++) {
  var loc = arrStr[i].indexOf(argname+"=");
  if(loc!=-1) {
    return arrStr[i].replace(argname+"=","").replace("?","");
    break;
  }
}
return "";
}
// jQuery 缓慢转到 Div
function go(index,time){
  if (time == null) { var time = 555; }
  $("html,body").animate({scrollTop: $("#"+index).offset().top}, time);
}
// 内容加载完毕后统一操作
$(document).ready(function(){
  $("a[href$='jpg'],a[href$='gif'],a[href$='png'],a[href$='jpeg'],a[href$='bmp'],a[href$='JPG'],a[href$='GIF'],a[href$='PNG'],a[href$='JPEG'],a[href$='BMP'],img[imgbox$='yes'],a[imgbox$='yes']").attr("data-lightbox","roadtrip");
  $("#sys_loading_tips").fadeOut(2000);
  if (urlget('jumpto')) {
    go(urlget('jumpto'));
  }
});
 //无名智者个人博客提示信息
document.write('<button class="btn btn-primary btn-lg" id="wabutton" style="display:none;" data-toggle="modal" data-target="#myModal"></button><div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><span class="modal-title" style="font-size:21px;" id="myModalLabel">提示信息</span></div><div class="modal-body" id="watext">系统错误</div><div class="modal-footer"><button type="button" class="btn btn-primary" id="waclose" data-dismiss="modal" style="width:100px;">关闭</button></div></div></div></div>');
function wa(text,title) {
if(text != null) {document.getElementById('watext').innerHTML = text;}
if(title != null) {document.getElementById('myModalLabel').innerHTML = title;}
$("#wabutton").click();
}
// JS基本内容复制
function wmzz_copy(text) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text", text)
	wa("该内容复制成功！",'复制本文地址');
  } else {
	wa('因为您的浏览器安全设置，复制失败。请您手动进行复制：<br/><br/><div class="input-group input-group-lg"><span class="input-group-addon">本文地址</span><input type="text" class="form-control" onclick="this.select();" value="'+text+'"></div>','复制本文地址');
  }
}
// 是/否 选择
function quest(ques) {
        if (!confirm(ques)) {
            window.event.returnValue = false;
        }
}
// 隐藏和显示内容
function hideorshow(sysid){
    if(sysid.style.display==""){
        sysid.style.display='none';
    }else{
        sysid.style.display='';
    }
}
/***
发表评论功能
***/
function qqcon() {
var qq=prompt('请填写您的QQ号，快速填写上述信息：','');
if(qq.length == 0){
            return false;
}
document.getElementsByName("comname")[0].value = qq;
document.getElementsByName("commail")[0].value = qq+"@qq.com";
document.getElementsByName("comurl")[0].value = "http://user.qzone.qq.com/"+qq;
}
////////////////////////////////
function wnmsg() {
 function RequestPermission (callback) {  
      window.webkitNotifications.requestPermission(callback);  
    }  
  
    function showNotification(){  
      if (window.webkitNotifications.checkPermission() > 0) {  
        RequestPermission(showNotification);  
      }  
      else {  
              window.webkitNotifications.createNotification().show();   
      }  
    }  
showNotification();
}
//底部公告栏控制
$("#ggb").click(function(){ $("#gg").show(); });
//AJAX评论
$(document).ready(function(){
	$("#commentform").submit(function(e){
	  $('#comment_submit').attr('disabled',true);
	  $('#comment_submit').html('<span class="glyphicon glyphicon-play"></span>&nbsp;&nbsp; 正在发表评论...');
	  $("#comsys").html('<font color="#3A99BB"><span class="glyphicon glyphicon-play"></span>&nbsp;&nbsp; 正在发表评论，请稍候...</font>');
	  if (document.getElementById('author')) {
	    var comname = document.getElementById('author').value;
	    var commail = document.getElementById('email').value;
	    var comurl  = document.getElementById('url').value;
	  } else {
	    var comname = null;
	    var commail = null;
	    var comurl  = null;
	  }
	  $.ajax({ 
	    async:true, 
	    url: './index.php?action=addcom', 
	    type: "POST", 
	    timeout: 30000,
	    data : {
	      'gid':document.getElementsByName('gid')[0].value,
	      'comname':comname,
	      'commail':commail,
	      'comurl':comurl,
	      'pid':document.getElementById('comment-pid').value,
	      'list':document.getElementById('list').value,
	      'comment':document.getElementById('write_comment_textarea').value,
	      'com_jzxx':document.getElementById('com_jzxx').value
	    },
	    dataType: 'html', 
	    timeout: 10000, 
	    success: function(data){
	    	var error_log = /<div class=\"main\">\n<p>(.*)<\/p><p>/.exec(data);
	       $('#comment_submit').removeAttr('disabled');
	  	   $('#comment_submit').html('<span class="glyphicon glyphicon-flag"></span>　发表评论');
	       if (error_log != null) {
	          $("#comsys").html('<font color="red"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;发表评论失败：'+error_log[1]+'</font>');
	       } else {
	          $("#comsys").html('<font color="green"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;发表评论成功！</font>');
	       }  
	   },
	    error: function(error){
	       $('#comment_submit').removeAttr('disabled');
	  	   $('#comment_submit').html('<span class="glyphicon glyphicon-flag"></span>　发表评论');
	       $("#comsys").html('<font color="red"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;发表评论失败：'+error+'</font>');
	    }
	  });
	  return false;
	});
});